package duoxiancheng;

/**
 * 线程不安全：数据有负数，数据有相同
 */
public class UnSafeTest01 {
    public static void main(String[] args) {
        //一份资源
        unsafe12306 w06= new unsafe12306();
        //多个代理
        new Thread(w06,"问问").start();
        new Thread(w06,"大幅度").start();
        new Thread(w06,"天天").start();
    }
}

class unsafe12306 implements Runnable{
    private int ticket = 10;
    private Boolean flag =true;

    @Override
    public void run() {
        while (flag){
            test();
        }
    }

    public void test(){
        if (ticket<0){
            flag=false;
            return;
        }
        try {//模拟网络延迟，高并发
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println( Thread.currentThread().getName()+"---->"+ticket--);
    }
}